package edu.mse.camel.client.session.actions;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;

import edu.mse.camel.client.session.plugin.Activator;
import edu.mse.camel.client.session.team.TEAMMEMBER_STATUS;
import edu.mse.camel.client.session.team.TeamList;
import edu.mse.camel.client.session.views.DialogMessages;
import edu.mse.camel.client.session.views.SessionDialog;

public class CreateSessionActionDelegate implements IObjectActionDelegate,
IViewActionDelegate {

	@Override
	public void init(IViewPart view) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void run(IAction action) {
		if (!TeamList.getInstance().getMyStatus().equals(TEAMMEMBER_STATUS.OFFLINE)) {
			if (!TeamList.getInstance().getMyStatus().equals(TEAMMEMBER_STATUS.SESSION)) {
				SessionDialog sessionDialog = new SessionDialog();
				sessionDialog.setTitleAndDesc();
			} else {
				ErrorDialog ed = new ErrorDialog(new Shell(),
						DialogMessages.DIALOG_ERROR,
						DialogMessages.AlreadyInSession, new Status(
								IStatus.ERROR, Activator.PLUGIN_ID,
								DialogMessages.AlreadyInSession),
						IStatus.ERROR);
				ed.open();				
			}
		} else {
			ErrorDialog ed = new ErrorDialog(
					new Shell(),
					DialogMessages.DIALOG_ERROR,
					DialogMessages.CreateSession_LoginError,
					new Status(IStatus.ERROR, Activator.PLUGIN_ID, DialogMessages.CreateSession_LoginError),
					IStatus.ERROR);
			ed.open();
		}
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
				
	}

}
